<?php

namespace app\admin\model\order;

use think\Model;


class OrderGoods extends Model
{

    

    

    // 表名
    protected $table = 'order_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_sales_text',
        'refund_status_text'
    ];
    

    
    public function getIsSalesList()
    {
        return ['0' => __('Is_sales 0'), '1' => __('Is_sales 1'), '2' => __('Is_sales 2')];
    }

    public function getRefundStatusList()
    {
        return ['0' => __('Refund_status 0'), '1' => __('Refund_status 1')];
    }


    public function getIsSalesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sales']) ? $data['is_sales'] : '');
        $list = $this->getIsSalesList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function spec()
    {
        return $this->belongsTo('app\admin\model\goods\GoodsSpec', 'goods_spec_id', 'goods_spec_id');
    }

}
